<template>
  <el-select
    v-model="value"
    :placeholder="props.placeholder"
    clearable
    filterable
    @change="change"
  >
    <el-option
      v-for="item in platformOptions"
      :key="item.platform_id"
      :label="item.platform_name"
      :value="item.platform_id"
    />
  </el-select>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";
const commonStore = useCommonStore();
const platformOptions = computed(() => {
  if (!commonStore.platformOptions) {
    commonStore.getPlatformList();
  }
  return commonStore.platformOptions || [];
});
const props = defineProps({
  modelValue: [String, Number, Array],
  placeholder: {
    type: String,
    default: "请选择",
  },
});

const value = computed(() => {
  return props.modelValue;
});

const emit = defineEmits(["update:modelValue", "change"]);
const change = (val) => {
  const item = platformOptions.value.find((i) => i.platform_id == val);
  emit("change", item?.platform_name || "");
  emit("update:modelValue", val);
};
</script>
